package com.wlc.thread;

    public class Hero {
        public String name;
        public float hp;

        public int damage;

        public Hero() {
        }

        public Hero(String name, float hp, int damage) {
            this.name = name;
            this.hp = hp;
            this.damage = damage;
        }

        public void attackHero(Hero h) {
          /*  try {
                //为了表示攻击需要时间，每次攻击暂停1000毫秒
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }*/
            h.hp -= damage;
            System.out.format("%s 正在攻击 %s, %s的血变成了 %.0f%n", name, h.name, h.name, h.hp);

            if (h.isDead()) {
                System.out.println(h.name + "死了！");
            }
        }

        public boolean isDead() {
            return 0 >= hp ? true : false;
        }

        /**
         * 波动拳
         */
        public static void punch(){
            while(true){

                for (int i = 0; i < 3; i++) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("开始第"+i+ "次发拳头");
                }
                try {
                    System.out.println("开始5秒充能");
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

        public static void main(String[] args) {
            punch();
        }
    }
